package com.itheima.mongodb.dao;

import com.itheima.mongodb.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PersonDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void savePerson(Person person){
        this.mongoTemplate.save(person);
    }

    public List<Person> queryPersonListByName(String name){
        Query query = new Query(Criteria.where("name").is(name));
        return this.mongoTemplate.find(query,Person.class);
    }

}
